package com.smasher.net.help

import com.tencent.mmkv.MMKV

class TokenManager private constructor() {

    private val mmkv: MMKV = MMKV.defaultMMKV()

    companion object {
        private const val TOKEN_KEY = "TOKEN"

        @JvmStatic
        val instance: TokenManager by lazy { Holder.INSTANCE }
    }

    private object Holder {
        val INSTANCE = TokenManager()
    }

    fun saveToken(token: String) {
        mmkv.encode(TOKEN_KEY, token)
    }

    fun getToken(): String? {
        return mmkv.decodeString(TOKEN_KEY)
    }

    fun clearToken() {
        mmkv.removeValueForKey(TOKEN_KEY)
    }
}